<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>定时器示例</title>
</head>
<body>

<input type="text" id="text">
<input type="button" value="开始" >
<input type="button" value="结束" >

<script>
  var time = 0;
  var seconde=0;
  var aInput = document.getElementsByTagName('input');
  var text = document.getElementById("text");
  var count = 1;//设置时间戳
  aInput[1].addEventListener("click",showTime)
  function showTime() {
    if(count){
      time = setInterval(function () {
        seconde++;
        text.value = seconde;
      }, 1000)
      count =0;
    }
  }
  aInput[2].addEventListener("click",stopTime)
  function stopTime(){
    clearInterval(time);
    count =1;
  }
</script>
</body>
</html>